package com.skit.common.retrofit

import com.skit.common.bean.StatusResult
import com.skit.common.bean.User
import retrofit2.Call
import retrofit2.http.*

/**
 * Author: shuike,
 * Email: shuike007@126.com,
 * Date: 2019/4/11.
 * PS: 用户相关网络请求
 */
interface UserProtocol {
    /**
     * 登录请求
     *
     * @param account 账号或邮箱
     * @param pwd     密码
     * @return 返回User
     */
    @POST("v1/user/login")
    @Headers("Content-Type:application/x-www-form-urlencoded; charset=utf-8")
    @FormUrlEncoded
    fun login(
        @Field("account") account: String,
        @Field("sessionKey") pwd: String,
        @Field("device") device: String
    ): Call<StatusResult<User>>

    @POST("v1/user/loginForUUID")
    @Headers("Content-Type:application/x-www-form-urlencoded; charset=utf-8")
    @FormUrlEncoded
    fun loginForUUID(
        @Field("uuid") uuid: String,
        @Field("token") token: String
    ): Call<StatusResult<User>>

    /**
     * 注册请求
     *
     * @param email    注册邮箱
     * @param username 注册用户名
     * @param pwd      密码
     * @return 返回JsonObject
     */
    @POST("v1/user/register")
    @Headers("Content-Type:application/x-www-form-urlencoded; charset=utf-8")
    @FormUrlEncoded
    fun register(
        @Field("email") email: String,
        @Field("name") username: String,
        @Field("pwd") pwd: String,
        @Field("stuNumber") stuNumber: String
    ): Call<StatusResult<String>>

    /**
     * 用ID和Token获取用户信息
     *
     * @param id    用户ID
     * @param token 　用户token
     * @return 返回User
     */
    @GET("v1/user/info")
    fun getUserInfo(
        @Query("id") id: Int,
        @Query("token") token: String
    ): Call<StatusResult<User>>

    @GET("v1/user/info")
    suspend fun getUserInfoSync(
        @Query("id") id: Int,
        @Query("token") token: String
    ): StatusResult<User>

    /**
     * 发送验证码
     *
     * @param email 用户邮箱
     * @return
     */
    @GET("v1/verification_code/send")
    fun sendVerificationCode(@Query("email") email: String): Call<StatusResult<String>>

    @GET("v1/user/activityNum")
    fun activityNum(@Query("id") uid: Int): Call<StatusResult<Map<String, Int>>>

    @GET("v1/user/admin")
    fun isAdmin(
        @Query("id") uid: Int,
        @Query("token") token: String
    ): Call<StatusResult<Boolean>>

    /**
     * 验证验证码
     *
     * @param email 用户邮箱
     * @param code  用户邮箱
     * @return
     */
    @GET("v1/verification_code/check")
    fun checkVerificationCode(
        @Query("email") email: String,
        @Query("code") code: String
    ): Call<StatusResult<String>>

    @POST("v1/user/update")
    @Headers("Content-Type:application/x-www-form-urlencoded; charset=utf-8")
    @FormUrlEncoded
    fun update(
        @Field("token") token: String,
        @Field("id") id: Int,
        @Field("value") value: String,
        @Field("data") data: String
    ): Call<StatusResult<String>>
}